package demo05_NotSafeCollections;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author kunkun
 * @className Test01_list
 * @Description 用于测试不安全的list类
 * @date 2025/3/5 20:32
 */
public class Test02_set {
    public static void main(String[] args) {


//        Map<String,Object> map = new HashMap<>();  //不安全的map

//        Map<String,Object> map = Collections.synchronizedMap(new HashMap<>()); //1. 使用Collections进行转换
        Map<String,Object> map = new ConcurrentHashMap<>() ;//2. 使用juc下的类


        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                map.put(UUID.randomUUID().toString().substring(0, 5),1);
                System.out.println(map);
            }, "Thread-" + i).start();
        }
    }
}
